const Router = require('koa-router')

const {success} = require('../../lib/helper')

const koaForm = require('formidable-upload-koa')

const {saveFile} = require('../../controller/utils')

const router = new Router({
    prefix: '/v1/utils'
})

router.post('/upload', koaForm(), async (ctx, next) => {
    const file = ctx.req.files['file']
    const {size, path, name, type} = file
    // const originPath = 'http://www.cawe-am.net/api'
    const originPath = 'https://rop.sdu.edu.cn/api'
    ctx.body = await saveFile({
        name,
        type,
        size,
        filePath: path
    },originPath)
})


module.exports = router
